/**
 * Created with JetBrains WebStorm.
 * User: hp
 * Date: 11/1/12
 * Time: 8:31 PM
 * To change this template use File | Settings | File Templates.
 */

setTimeout(function(){
    initStores();

    var _store = Ext.StoreMgr.lookup('AAWE.App.List.Store.CheckListStore');

    console.log(_store.data.length)

    initDefaultList();
}, 1000);

var defaultList = [{
    name: 'going out',
    items: ['milk/formula', 'baby food', 'bib', 'bowl and spoon', 'soft tissues', 'wipes', 'diapers', 'sunblock', 'pacifier', 'water', 'lotion']
}, {
    name: 'travel',
    items: ['milk/formula', 'baby food', 'bib', 'bowl and spoon', 'soft tissues', 'wipes', 'diapers', 'sunblock', 'pacifier', 'water', 'lotion', 'favorite toy', 'blanket', 'nail clip']
}, {
    name: 'doctor\'s visit',
    items: ['immunization card', 'insurance card', 'diapers', 'wipes', 'milk/formula', 'bib', 'pacifier', 'water']
}];

function initStores() {
    (new AAWE.App.Profile.Store.ChildrenStore({ model: 'AAWE.App.Profile.Model.Child' })).load();
    (new AAWE.App.Context.Store.ContextStore({ model: 'AAWE.App.Context.Model.Context' })).load();
    (new AAWE.App.List.Store.CheckListStore({ model: 'AAWE.App.List.Model.CheckList' })).load();
    (new AAWE.App.List.Store.CheckListItemStore({ model: 'AAWE.App.List.Model.CheckListItem' })).load();
}

function initDefaultList() {
    var _listStore = Ext.StoreMgr.lookup('AAWE.App.List.Store.CheckListStore');
    var _listItemStore = Ext.StoreMgr.lookup('AAWE.App.List.Store.CheckListItemStore');

    var _list, _item, _id, i, j, _temp;
    for (i = 0; i < defaultList.length; i++) {
        _list = defaultList[i];
        _temp = _listStore.add({ name: _list.name, editing: false });
        _id = _temp[0].data.id;
        for (j = 0; j < _list.items.length; j++) {
            _item = _list.items[j];
            _listItemStore.add({ itemname: _item, listId: _id, isChecked: false, editing: false });
        }
    }
}